<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Struct shell</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../../boost_process/v2.html#header.boost.process.v2.shell_hpp" title="Header &lt;boost/process/v2/shell.hpp&gt;">
<link rel="prev" href="basic_process_handle/rebind_executor.html" title="Struct template rebind_executor">
<link rel="next" href="shell_category.html" title="Global shell_category">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="basic_process_handle/rebind_executor.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../boost_process/v2.html#header.boost.process.v2.shell_hpp"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="shell_category.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.process.v2.shell"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Struct shell</span></h2>
<p>boost::process::v2::shell — Utility to parse commands. </p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../../boost_process/v2.html#header.boost.process.v2.shell_hpp" title="Header &lt;boost/process/v2/shell.hpp&gt;">boost/process/v2/shell.hpp</a>&gt;

</span>
<span class="keyword">struct</span> <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">{</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="keyword">char</span>          <a name="boost.process.v2.shell.char_type"></a><span class="identifier">char_type</span><span class="special">;</span>
  <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="special">*</span> <a name="boost.process.v2.shell.args_type"></a><span class="identifier">args_type</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="shell.html#boost.process.v2.shellconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="shell.html#idm9438-bb"><span class="identifier">shell</span></a><span class="special">(</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Char<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
    <a class="link" href="shell.html#idm9439-bb"><span class="identifier">shell</span></a><span class="special">(</span><span class="identifier">basic_string_view</span><span class="special">&lt;</span> <span class="identifier">Char</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="shell.html#idm9445-bb"><span class="identifier">shell</span></a><span class="special">(</span><a class="link" href="basic_cstring_ref.html" title="Struct template basic_cstring_ref">basic_cstring_ref</a><span class="special">&lt;</span> <span class="identifier">char_type</span> <span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="shell.html#idm9449-bb"><span class="identifier">shell</span></a><span class="special">(</span><span class="identifier">basic_string_view</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">conditional</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">char_type</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="keyword">wchar_t</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="shell.html#idm9452-bb"><span class="identifier">shell</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
  <a class="link" href="shell.html#idm9462-bb"><span class="identifier">shell</span></a><span class="special">(</span><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;&amp;</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span> <a class="link" href="shell.html#idm9456-bb"><span class="keyword">operator</span><span class="special">=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span>
  <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span> <a class="link" href="shell.html#idm9466-bb"><span class="keyword">operator</span><span class="special">=</span></a><span class="special">(</span><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;&amp;</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <a class="link" href="shell.html#idm9472-bb"><span class="special">~</span><span class="identifier">shell</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="shell.html#idm9413-bb">public member functions</a></span>
  <span class="keyword">int</span> <a class="link" href="shell.html#idm9414-bb"><span class="identifier">argc</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a class="link" href="shell.html#idm9416-bb"><span class="identifier">argv</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a class="link" href="shell.html#idm9418-bb"><span class="identifier">begin</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a class="link" href="shell.html#idm9420-bb"><span class="identifier">end</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="shell.html#idm9422-bb"><span class="identifier">empty</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a class="link" href="../../container/flat_map.html#idm9424-bb"><span class="identifier">size</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">args_type</span> <a class="link" href="shell.html#idm9426-bb"><span class="identifier">args</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Environment <span class="special">=</span> <a class="link" href="environment/current_view.html" title="Struct current_view">environment::current_view</a><span class="special">&gt;</span> 
    <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span> <a class="link" href="shell.html#idm9429-bb"><span class="identifier">exe</span></a><span class="special">(</span><span class="identifier">Environment</span> <span class="special">&amp;&amp;</span> <span class="special">=</span> <span class="identifier">environment</span><span class="special">::</span><span class="identifier">current</span><span class="special">(</span><span class="special">)</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="shell.html#idm9473-bb">private member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="shell.html#idm9474-bb"><span class="identifier">parse_</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.29.12.8.13.3.4"></a><h2>Description</h2>
<p>This utility class parses command lines into tokens and allows users to executed based on textual inputs.</p>
<p>In v1, this was possible directly when starting a process, but has been removed based on the security risks associated with this.</p>
<p>By making the shell parsing explicitly, it encourages a user to run a sanity check on the executable before launching it.</p>
<p><b>Example. </b></p>
<pre class="programlisting"><span class="identifier">asio</span><span class="special">::</span><span class="identifier">io_context</span> <span class="identifier">ctx</span><span class="special">;</span>

<span class="keyword">auto</span> <span class="identifier">cmd</span> <span class="special">=</span> <span class="identifier">shell</span><span class="special">(</span><span class="string">"my-app --help"</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">auto</span> <span class="identifier">exe</span> <span class="special">=</span> <span class="identifier">cmd</span><span class="special">.</span><span class="identifier">exe</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">check_if_malicious</span><span class="special">(</span><span class="identifier">exe</span><span class="special">)</span><span class="special">;</span>

<span class="identifier">process</span> <span class="identifier">proc</span><span class="special">{</span><span class="identifier">ctx</span><span class="special">,</span> <span class="identifier">exe</span><span class="special">,</span> <span class="identifier">cmd</span><span class="special">.</span><span class="identifier">args</span><span class="special">(</span><span class="special">)</span><span class="special">}</span><span class="special">;</span>
</pre>
<p> </p>
<p>
</p>
<div class="refsect2">
<a name="id-1.3.29.12.8.13.3.4.6"></a><h3>
<a name="boost.process.v2.shellconstruct-copy-destruct"></a><code class="computeroutput">shell</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><pre class="literallayout"><a name="idm9438-bb"></a><span class="identifier">shell</span><span class="special">(</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Char<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
  <a name="idm9439-bb"></a><span class="identifier">shell</span><span class="special">(</span><span class="identifier">basic_string_view</span><span class="special">&lt;</span> <span class="identifier">Char</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> input<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a name="idm9445-bb"></a><span class="identifier">shell</span><span class="special">(</span><a class="link" href="basic_cstring_ref.html" title="Struct template basic_cstring_ref">basic_cstring_ref</a><span class="special">&lt;</span> <span class="identifier">char_type</span> <span class="special">&gt;</span> input<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a name="idm9449-bb"></a><span class="identifier">shell</span><span class="special">(</span><span class="identifier">basic_string_view</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">conditional</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">is_same</span><span class="special">&lt;</span> <span class="identifier">char_type</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">value</span><span class="special">,</span> <span class="keyword">wchar_t</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <span class="special">&gt;</span> input<span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a name="idm9452-bb"></a><span class="identifier">shell</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a name="idm9462-bb"></a><span class="identifier">shell</span><span class="special">(</span><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;&amp;</span> lhs<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span> <a name="idm9456-bb"></a><span class="keyword">operator</span><span class="special">=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">delete</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;</span> <a name="idm9466-bb"></a><span class="keyword">operator</span><span class="special">=</span><span class="special">(</span><a class="link" href="shell.html" title="Struct shell">shell</a> <span class="special">&amp;&amp;</span> lhs<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><a name="idm9472-bb"></a><span class="special">~</span><span class="identifier">shell</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre></li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.29.12.8.13.3.4.7"></a><h3>
<a name="idm9413-bb"></a><code class="computeroutput">shell</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><pre class="literallayout"><span class="keyword">int</span> <a name="idm9414-bb"></a><span class="identifier">argc</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a name="idm9416-bb"></a><span class="identifier">argv</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a name="idm9418-bb"></a><span class="identifier">begin</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="identifier">char_type</span> <span class="special">*</span><span class="special">*</span> <a name="idm9420-bb"></a><span class="identifier">end</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm9422-bb"></a><span class="identifier">empty</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <a name="idm9424-bb"></a><span class="identifier">size</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">args_type</span> <a name="idm9426-bb"></a><span class="identifier">args</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Native representation of the arguments to be used - excluding the executable. </li>
<li class="listitem"><pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Environment <span class="special">=</span> <a class="link" href="environment/current_view.html" title="Struct current_view">environment::current_view</a><span class="special">&gt;</span> 
  <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span> <a name="idm9429-bb"></a><span class="identifier">exe</span><span class="special">(</span><span class="identifier">Environment</span> <span class="special">&amp;&amp;</span> env <span class="special">=</span> <span class="identifier">environment</span><span class="special">::</span><span class="identifier">current</span><span class="special">(</span><span class="special">)</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.29.12.8.13.3.4.8"></a><h3>
<a name="idm9473-bb"></a><code class="computeroutput">shell</code> private member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <a name="idm9474-bb"></a><span class="identifier">parse_</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre></li></ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2006-2012 Julio M. Merino Vidal, Ilya Sokolov,
      Felipe Tanus, Jeff Flinn, Boris Schaeling<br>Copyright © 2016 Klemens D. Morgenstern<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="basic_process_handle/rebind_executor.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../boost_process/v2.html#header.boost.process.v2.shell_hpp"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="shell_category.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
